home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 23 / CU Amiga - Super CD-ROM 23 (June 1998).iso / CreatingGames / Utilities / E / PlayTHX / src / PlayTHX.e < prev    next >
Encoding:
Text File  |  1997-10-07  |  1.7 KB  |  74 lines

  1. MODULE 'tools/file', 'tools/thx-play', 'arp', 'exec/memory', 'dos/dos'
  2.  
  3. ENUM ARG_FILES,ARG_NOREP,ARG_FADE
  4.  
  5. PROC main() HANDLE
  6.   DEF args:PTR TO LONG,rdargs=0,template,file,files:PTR TO LONG
  7.  
  8.   args:=[0,0,0]; template:='PLAYLIST/M,NOREPEAT/S,FADE/S'
  9.   IF KickVersion(36)
  10.     rdargs:=ReadArgs(template,args,NIL)
  11.   ELSE
  12.     IF arpbase:=OpenLibrary('arp.library',39)
  13.       GaDS(arg,StrLen(arg),template,args,NIL)
  14.     ELSE
  15.       WriteF('Needs arp.library v39\n')
  16.       RETURN 20
  17.     ENDIF
  18.   ENDIF
  19.  
  20.   IF files:=args[ARG_FILES] THEN WHILE file:=files[]++ DO play(file,args[ARG_NOREP],args[ARG_FADE])
  21.  
  22.   Raise(0)
  23. EXCEPT
  24.   thxFree() -> only free all resources _ONCE_ :)
  25.   IF arpbase THEN CloseLibrary(arpbase)
  26.   IF rdargs  THEN FreeArgs(rdargs)
  27. ENDPROC
  28.  
  29. PROC play(name,norep,fade)
  30.   DEF mod,len,vol,sig,cont=TRUE
  31.  
  32.   mod,len:=readfile(name)
  33.   IF mod=0
  34.     WriteF('Can\at read file "\s"\n"',name)
  35.     RETURN
  36.   ENDIF
  37.  
  38.   WriteF('Now playing "\s".\nPress CTRL-C to skip, CTRL-D to stop. '+
  39.          'CTRL-F will fast-forward.\n',name)
  40.  
  41.   IF thxInit(mod)<>0
  42.     WriteF('Can\at start player.\n')
  43.     freefile(mod)
  44.     RETURN
  45.   ENDIF
  46.  
  47.   -> if we are not to repeat, then set THX to break us at the end.
  48.   IF norep THEN thxSignalEnd(SIGBREAKF_CTRL_C)
  49.  
  50.   thxSetVolume(64)
  51.   thxPlay() -> start play
  52.  
  53.   WHILE cont
  54.     sig:=Wait(SIGBREAKF_CTRL_C OR SIGBREAKF_CTRL_D OR SIGBREAKF_CTRL_F)
  55.     IF sig AND SIGBREAKF_CTRL_F
  56.       thxWind(1)
  57.     ELSE
  58.       cont:=FALSE
  59.     ENDIF
  60.   ENDWHILE
  61.  
  62.   IF fade
  63.     FOR vol:=64 TO 0 STEP -1
  64.       WaitTOF()
  65.       thxSetVolume(vol)
  66.     ENDFOR
  67.   ENDIF
  68.  
  69.   thxStop() -> no longer use the mod, we can free the memory.
  70.  
  71.   freefile(mod)
  72.   IF sig AND SIGBREAKF_CTRL_D THEN Raise("stop") -> pop out of loop in main()
  73. ENDPROC
  74.